(function(){
		var currentP;
		$(document).ready(function(){
				for(var i=1;i<=30;i++)
					$("body").append("<div id='id"+i+"' class='box'><img src='photo/thumb/"+i+".jpg'></div>");
				$("#close").click(function (){
					$(".shadow").hide();
				});
				$("img").not("#close").click(function(){
					var idx=$("img").not(".shadow img").index(this)+1;
					currentP=idx;
					//console.log(currentP);
					$(".shadow #photo").attr({"src":"photo/"+idx+".jpg"});
					if($(this).attr("class")=="ls"){
						//console.log("hello");
						$(".shadow #photo").attr({"style":"margin-top:100px;"});
					}else if($(this).attr("class")=="pt"){
						$(".shadow #photo").removeAttr("style");
					}
					$(".shadow").show("10000");
				});
			});
		
		$(window).load(function(){
			$("img").not(".shadow img").length
			var imgs=$("img").not(".shadow img");
			for(var i=0;i<=30;i++){
				var node=imgs.eq(i);
				var h=node.height();
				var w=node.width();
				if(h>w){
					node.addClass("pt");
				}else {
					node.addClass("ls");
				}
			}
			
			$(".changeP").click(function(){
					switch($(this).attr("id")){
						case "preP":
						currentP-=1;
						//console.log(currentP);
						if(currentP<1){
							currentP=30;
						}
						//console.log($("img").not(".shadow img").eq(currentP-1).attr("src"));
						if($("img").not(".shadow img").eq(currentP-1).attr("class")=="ls"){
						$(".shadow #photo").attr({"style":"margin-top:100px;"});
						}else if($("img").not(".shadow img").eq(currentP-1).attr("class")=="pt"){
						$(".shadow #photo").removeAttr("style");
						}
						$(".shadow #photo").attr({"src":"photo/"+(currentP)+".jpg"});
						break;
						case "nextP":
						currentP+=1;
						//console.log(currentP);
						if(currentP>30){
							currentP=1;
						}
						//console.log($("img").not(".shadow img").eq(currentP-1).attr("src"));
						if($("img").not(".shadow img").eq(currentP-1).attr("class")=="ls"){
						//console.log("hello");
						$(".shadow #photo").attr({"style":"margin-top:100px;"});
						}else if($("img").not(".shadow img").eq(currentP-1).attr("class")=="pt"){
						$(".shadow #photo").removeAttr("style");
						}
						$(".shadow #photo").attr({"src":"photo/"+(currentP)+".jpg"});
						break;
					}
				});
		});
})();
